home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 001-025 / disk_023 / ver30 / tty / intuition / gnuttykbd.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  6KB  |  224 lines

  1. /*
  2.  * Name:    MicroEMACS
  3.  *         Amiga virtual terminal keyboard, default console keymap.
  4.  * Version:    31
  5.  * Last edit:    20-Apr-86
  6.  * Created:    19-Apr-86 ...!ihnp4!seismo!ut-sally!ut-ngp!mic
  7.  *            Supports all the default console device
  8.  *            (RAW:) input codes for the Amiga keyboard.
  9.  * Modified:    20-Apr-86 ...!ihnp4!seismo!ut-sally!ut-ngp!mic
  10.  *        [UT-14]    Added processing for GR_to_META, so
  11.  *            characters in the alternate character set
  12.  *            can automatically map to META characters.
  13.  *            This is a rather nice thing to have...
  14.  *        Added KMENU to key definitions, bound to amigamenu().
  15.  *        This goes with the Intuition terminal driver.
  16.  */
  17. #include    "def.h"
  18.  
  19. #define    ESC    0x1B            /* Escape, arrows et al.    */
  20. #define    CSI    0x9B            /* Amiga CSI            */
  21.  
  22. /*
  23.  * The function keys on the Amiga send back
  24.  * escape sequences of the form <ESC>[code~, where code
  25.  * is a one or two-character code for the key.  To make
  26.  * it easier to decode, we place the internal key values
  27.  * for these codes in this table.
  28.  */
  29.  
  30. short    consolemap[] = {
  31.     KF1,        KF2,        KF3,        KF4,
  32.     KF5,        KF6,        KF7,        KF8,
  33.     KF9,        KF10,        KSF1,        KSF2,
  34.     KSF3,        KSF4,        KSF5,        KSF6,
  35.     KSF7,        KSF8,        KSF9,        KSF10
  36. };
  37. #define    NFUNCKEYS ((sizeof consolemap)/(sizeof consolemap[0]))
  38.  
  39. /*
  40.  * Names for the keys with basic keycode
  41.  * between KFIRST and KLAST (inclusive). This is used by
  42.  * the key name routine in "kbd.c".  KFIRST is KRANDOM, which
  43.  * we don't bind anything useful to.  "Amiga Menus" is
  44.  * special; we implement menus as another function key,
  45.  * but there isn't really any "MENU" key on the keyboard.
  46.  */
  47. char    *keystrings[] = {
  48.     NULL,        "F1",        "F2",        "F3",
  49.     "F4",        "F5",        "F6",        "F7",
  50.     "F8",        "F9",        "F10",        "Shift-F1",
  51.     "Shift-F2",    "Shift-F3",    "Shift-F4",    "Shift-F5",
  52.     "Shift-F6",    "Shift-F7",    "Shift-F8",    "Shift-F9",
  53.     "Shift-F10",    "Up",        "Shift-Up",    "Down",
  54.     "Shift-Down",    "Left",        "Shift-Left",    "Right",
  55.     "Shift-Right",    "Help",        "The Menu",    "The Mouse"
  56. };
  57.  
  58. /*
  59.  * Read in a key, doing the low level mapping
  60.  * of ASCII code to 11 bit code. This level deals with
  61.  * mapping the special keys into their spots in the C1
  62.  * control area. The C0 controls go right through, and
  63.  * get remapped by "getkey".
  64.  *
  65.  * If GR_to_META is TRUE, characters in the Amiga alternate
  66.  * character set get mapped to META characters.  If FALSE,
  67.  * they get sent straight through.
  68.  */
  69.  
  70. #ifdef AS_DISTRIBUTED
  71. extern    int    GR_to_META;    /* defined in "kbd.c" */
  72. #else
  73. int    GR_to_META = TRUE;    /* not in *MY* "kbd.c"; Fred Fish */
  74. #endif
  75.  
  76. getkbd()
  77. {
  78.     register int    c;
  79.     register int    n;
  80. loop:
  81.     c = ttgetc();
  82.     if (c == CSI) {
  83.         c = ttgetc();
  84.         if (c == 'P') {            /* mouse sequence    */
  85.             ttgetc();        /* First because it's   */
  86.             return (KMOUSE);    /* used a lot.        */
  87.         }
  88.         if (c == 'M') {            /* (fake) menu key    */
  89.             ttgetc();        /* discard '~'        */
  90.             return (KMENU);
  91.         }
  92.         /* Arrow keys */
  93.         if (c == 'A')
  94.             return (KUP);
  95.         if (c == 'B')
  96.             return (KDOWN);
  97.         if (c == 'C')
  98.             return (KRIGHT);
  99.         if (c == 'D')
  100.             return (KLEFT);
  101.         if (c == 'T')
  102.             return (KSUP);
  103.         if (c == 'S')
  104.             return (KSDOWN);
  105.         if (c == '?') {            /* HELP key        */
  106.             ttgetc();        /* discard '~'        */
  107.             return (KHELP);
  108.         }
  109.         /* Shifted left, right arrow */
  110.         if (c == ' ') {
  111.             c = ttgetc();
  112.             if (c == 'A' || c == '@')
  113.                 return (c == 'A') ? (KSLEFT) : (KSRIGHT);
  114.             goto loop;        /* try again, sucker */
  115.         }
  116.  
  117.         /* Function keys    */
  118.         if (c >= '0' && c <= '9') {
  119.             n = 0;
  120.             do {
  121.                 n = 10*n + c - '0';
  122.                 c = ttgetc();
  123.             } while (c>='0' && c<='9');
  124.             if (c == '~' && n < NFUNCKEYS) {
  125.                 c = consolemap[n];
  126.                 if (c != KRANDOM)
  127.                     return (c);
  128.                 goto loop;
  129.             }
  130.             else 
  131.                 goto loop;    /* Try again */
  132.         }
  133.         goto loop;        /* Try again */
  134.     }
  135.  
  136.     /* Meta keys -- also check for high bit set */
  137.     if ((c == ESC) || (GR_to_META && (c & 0x80))) {
  138.         if (c == ESC)
  139.             c = ttgetc();
  140.         c &= 0x7F;            /* Strip high bit    */
  141.         if (ISLOWER(c) != FALSE)    /* Copy the standard    */
  142.             c = TOUPPER(c);        /* META code.        */
  143.         if (c>=0x00 && c<=0x1F)
  144.             c = KCTRL | (c+'@');
  145.         return (KMETA | c);
  146.     }
  147.     return (c);
  148. }
  149.  
  150. /*
  151.  * Terminal specific keymap initialization.
  152.  * Attach the special keys to the appropriate built
  153.  * in functions. Bind all of the assigned graphics in the
  154.  * Amiga alternate character set to self-insert.
  155.  *
  156.  * Bind the fake KMENU code to amigamenu() to do
  157.  * menu selection as transparently as possible.
  158.  * Ditto with KMOUSE. As is the case of all the
  159.  * keymap routines, errors are very fatal.
  160.  */
  161.  
  162. extern    int    amigamenu();        /* Defined by "ttymenu.c"     */
  163. extern    int    amigamouse();        /* Defined by "ttymouse.c"    */
  164.  
  165. ttykeymapinit()
  166. {
  167.     register SYMBOL    *sp;
  168.     register int    i;
  169.  
  170.     /* ADD these bindings instead of duplicating it */
  171.     keyadd(KMENU,    amigamenu,    "amiga-menu");
  172.     keyadd(KMOUSE,    amigamouse,    "amiga-mouse");
  173.  
  174.     keydup(KUP,    "previous-line");
  175.     keydup(KDOWN,    "next-line");
  176.     keydup(KRIGHT,    "forward-char");
  177.     keydup(KLEFT,    "backward-char");
  178.     keydup(KHELP,    "help");
  179. #ifdef UNIMPLEMENTED
  180.     keydup(KSUP,    "goto-bop");
  181.     keydup(KSDOWN,    "goto-eop");
  182. #endif
  183.     keydup(KSRIGHT,    "forward-word");
  184.     keydup(KSLEFT,    "backward-word");
  185.  
  186.     keydup(KF1,    "down-window");
  187.     keydup(KF2,    "scroll-up");
  188.     keydup(KF3,    "enlarge-window");
  189.     keydup(KF4,    "other-window");
  190.     keydup(KF5,    "split-window-vertically");
  191.     keydup(KF6,    "find-file");
  192.     keydup(KF7,    "file-buffer");
  193.     keydup(KF8,    "start-kbd-macro");
  194.     keydup(KF9,    "global-set-key");
  195.     keydup(KF10,    "emacs-version");
  196.  
  197.     keydup(KSF1,    "up-window");
  198.     keydup(KSF2,    "scroll-down");
  199.     keydup(KSF3,    "shrink-window");
  200.     keydup(KSF4,    "back-window");
  201.     keydup(KSF5,    "delete-other-windows");
  202.     keydup(KSF6,    "file-file-read-only");
  203.     keydup(KSF7,    "write-file");
  204.     keydup(KSF8,    "end-kbd-macro");
  205.     keydup(KSF9,    "describe-bindings");
  206.     keydup(KSF10,    "save-buffers-kill-emacs");
  207.  
  208.     /*
  209.      * Bind all positions that correspond
  210.      * to characters in the Amiga alternate
  211.      * character set to "ins-self". These characters may
  212.      * be used just like any other character.
  213.      */
  214.  
  215.     if ((sp=symlookup("self-insert-command")) == NULL)
  216.         abort();
  217.     for (i=0xA0; i<0xFF; ++i) {
  218.         if (binding[i] != NULL)
  219.             abort();
  220.         binding[i] = sp;
  221.         ++sp->s_nkey;
  222.     }
  223. }
  224.